package groupchat.utils;

import groupchat.dao.UserDao;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

//git merge 测试
public class SqlSessionUtils {
    private static SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
    private static SqlSessionFactory sqlSessionFactory;

    static {
        String resource = "mybatis-config.xml";
        InputStream inputStream = SqlSessionUtils.class.getClassLoader().getResourceAsStream(resource);
        sqlSessionFactory = sqlSessionFactoryBuilder.build(inputStream);
        System.out.println("mybatis启动完毕");
    }

    public static SqlSession getSqlSession() {
        return sqlSessionFactory.openSession();
    }

    public static void main(String[] args) {
        UserDao userDao = getSqlSession().getMapper(UserDao.class);
        System.out.println(userDao.findByName("邢宇飞"));
    }
}
